package aps.module_Machines;

//Java
import org.lwjgl.opengl.GL11;

//Minecraft
import net.minecraft.src.GuiContainer;
import net.minecraft.src.InventoryPlayer;

//Forge
import net.minecraftforge.client.MinecraftForgeClient;

//APS
import aps.BuildcraftAPS;


public class GuiPoweredFurnace extends GuiContainer
{
	private TileEntityPoweredFurnace furnaceInventory;
	String guiFile = BuildcraftAPS.imageFilesRoot + "PoweredFurnaceGUI.png";
	
	public GuiPoweredFurnace(TileEntityPoweredFurnace furnace, InventoryPlayer playerInv)
	{
		super(new ContainerPoweredFurnace(furnace, playerInv));
        furnaceInventory = furnace;
	}
	
	protected void drawGuiContainerForegroundLayer(int x, int y)
    {
        fontRenderer.drawString("Inventory", 8, (ySize - 96) + 2, 0x404040);
    }
	
	protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
    {
        int guiTex = mc.renderEngine.getTexture(guiFile);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        mc.renderEngine.bindTexture(guiTex);
        int topLeftX = (width - xSize) / 2;
        int topLeftY = (height - ySize) / 2;
        drawTexturedModalRect(topLeftX, topLeftY, 0, 0, xSize, ySize);
        displayTempGauge(topLeftX, topLeftY, 79, 11, furnaceInventory.getCookProgressScaled(64));
    }
	
	private void displayTempGauge(int TopLeftX, int TopLeftY, int GaugeTopLeftX, int GaugeTopLeftY, int BarHeight)
	{
		MinecraftForgeClient.preloadTexture(guiFile);
		
		int start = 0;

		while (true)
		{
			int x = 0;

			if (BarHeight > 8) {
				x = 8;
				BarHeight -= 8;
			} else {
				x = BarHeight;
				BarHeight = 0;
			}

			drawTexturedModalRect(TopLeftX + GaugeTopLeftX, TopLeftY + GaugeTopLeftY + 64 - x - start, 176, 8 - x, 8, x); //The 58 is the gauge height
			start = start + 8;

			if (x == 0 || BarHeight == 0) {
				break;
			}
		} //This while draws the repeating gauge graphic.
    }
}